import axios from 'axios'
// import Element from 'element-ui'
import VueCookie from 'vue-cookie';
import router from "./router";
// import {getToken} from 'src/utils/auth.js'
//基础url
// axios.defaults.baseURL="http://if.vaiwan.com"
// axios.defaults.baseURL="http://121.196.34.140"
// axios.defaults.baseURL="https://www.ifyyf.com"
const vc=this;
// axios.defaults.baseURL="http://139.159.253.126:8088/blog-server"
axios.defaults.baseURL="http://localhost:8088/blog-server"

/**
 * 前置拦截
 */
axios.interceptors.request.use(config=>{
    const Token = VueCookie.get('token');
    console.log("token.....",Token);
    if(Token){
        config.headers['access_token'] = Token;
    }
    return config
})

/**
 * 后置拦截
 * 每次使用axios都会访问一次这个方法
 */
axios.interceptors.response.use(response=>{
    // console.log("=======")
    // console.log(response)
    // console.log("=======")
    if(response.data.code===200){
        return response
    } else if (response.data.code===401) {
        router.push('/Login')
    }
    else{
        vc.$message.error(response.data.msg);
        //return Promise.reject(response.data.msg)
    }
})
